package com.admin.controller;


import com.admin.entity.Admin;
import com.admin.entity.Theme;
import com.admin.service.IThemeService;
import com.bean.ResponseBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class ShenheControl
{

    @Autowired
    private IThemeService themeService;

    @Autowired
    private HttpServletRequest request;

    /**
     *
     * @param msg  同意  or 不同意
     * @return
     */
    @RequestMapping("/welcome_audit")
    public ResponseBean shenHeWelcome(String id ,String msg)
    {
        Admin admin = (Admin)request.getSession().getAttribute("admin");
        if (admin==null || admin.getAdminParent()==null || admin.getAdminParent()!=0)
        {
            if (admin!=null && admin.getShenhe()==1){

            }
            else{
                return new ResponseBean(401,"没有权限",null);
            }
        }

        if (id==null || msg==null)
        {
            return new ResponseBean(500,"缺少参数",null);
        }


        Theme theme = themeService.getById(id);
        if (theme==null)
        {
            return new ResponseBean(500,"不存在的审核",null);
        }

        if ("同意".equals(msg))
        {
            theme.setThemeWelcomePageStatus("审核通过");
            theme.setThemeWelcomePageAndroidchecked(theme.getThemeWelcomePageAndroidunchecked());
            theme.setThemeWelcomePagePcchecked(theme.getThemeWelcomePagePcunchecked());
        }
        else if ("不同意".equals(msg))
        {
            theme.setThemeWelcomePageStatus("审核未通过");
        }
        else
        {
            return new ResponseBean(500,"缺少参数",null);
        }

        themeService.updateTheme(theme);

        return new ResponseBean(200,"操作成功",null);


    }


    /**
     *
     * @param msg  同意  or 不同意
     * @return
     */
    @RequestMapping("/index_audit")
    public ResponseBean index_audit(String id ,String msg)
    {
        Admin admin = (Admin)request.getSession().getAttribute("admin");
        if (admin==null || admin.getAdminParent()==null || admin.getAdminParent()!=0)
        {

            if (admin!=null  && admin.getShenhe()==1){

            }
            else{
                return new ResponseBean(401,"没有权限",null);
            }
        }

        if (id==null || msg==null)
        {
            return new ResponseBean(500,"缺少参数",null);
        }


        Theme theme = themeService.getById(id);
        if (theme==null)
        {
            return new ResponseBean(500,"不存在的审核",null);
        }

        if ("同意".equals(msg))
        {
            //修改状态，并复制
            theme.setThemeShenheStatus("审核通过");
            theme.setThemeAuditPcAudited(theme.getThemeAuditPcUnaudited());
            theme.setThemeAuditAndroidAudited(theme.getThemeAuditAndroidUnaudited());
        }
        else if ("不同意".equals(msg))
        {
            theme.setThemeShenheStatus("审核未通过");
        }
        else
        {
            return new ResponseBean(500,"缺少参数",null);
        }

        themeService.updateTheme(theme);

        return new ResponseBean(200,"操作成功",null);


    }




}
